//
//  BK_Confirm_Order_Coupons_Cell_Header.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/2/21.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_Confirm_Order_Coupons_Cell_Header.h"
#import "BK_Confirm_Order_Common.h"
#import "BK_OD_Color.h"
@implementation BK_Confirm_Order_Coupons_Cell_Header
{
    UILabel *_coupons;
    UILabel *_couponsType;
    UILabel *_couponsCount;
    UIImageView *_rightArrow;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self initialize];
    }
    return self;
}

-(void)initialize
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    _coupons = [[UILabel alloc] init];
    _coupons.backgroundColor = [UIColor clearColor];
    _coupons.textColor = kOrderBlack1;
    _coupons.font = UIFontCustom(15);
    _coupons.text = kOrderLocalizeString(@"BKOrderCoupons");
    [self.contentView addSubview:_coupons];
    
    /*
     * x张可用
     */
    _couponsCount = [[UILabel alloc] init];
//    _couponsCount.backgroundColor = HexColor(0xEC5544);
    _couponsCount.backgroundColor = BK_OD_Red;
    _couponsCount.textColor = [UIColor whiteColor];
    _couponsCount.textAlignment = NSTextAlignmentCenter;
    _couponsCount.font = UIFontCustom(10);
    [self.contentView addSubview:_couponsCount];
    
    _couponsType = [[UILabel alloc] init];
    _couponsType.backgroundColor = [UIColor clearColor];
//    _couponsType.textColor = kOrderBlack1;
    _couponsType.textColor = BK_OD_Gray;
    _couponsType.font = UIFontCustom(14);
    [self.contentView addSubview:_couponsType];
    
    _rightArrow = [[UIImageView alloc] init];
    [self.contentView addSubview:_rightArrow];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self addGestureRecognizer:tap];
    
    [self makeConstraints];
}

- (void)tapAction:(UIGestureRecognizer *)recognizer
{
    if (self.delegate && [self.delegate conformsToProtocol:@protocol(BK_Confirm_Order_Coupons_Delegate)])
    {
        [self.delegate BK_Confirm_Order_Coupons_DidSelected:self];
    }
}

- (void)makeConstraints
{
    [_coupons mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(ApplicationBackGauge);
        make.centerY.equalTo(self.contentView);
    }];
    
    [_couponsCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_coupons.mas_right).offset(10);
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(48);
        make.height.mas_equalTo(18);
    }];
    
    [_rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView).offset(-ApplicationBackGauge);
        make.centerY.equalTo(self.contentView);
    }];
    
    [_couponsType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_rightArrow.mas_left).offset(-5);
        make.centerY.equalTo(self.contentView);
    }];
    
}

- (void)fillData:(id)data
{
    BKOrderCurrentCoupon *cCoupon = data;
    _rightArrow.image = [UIImage imageNamed:@"BKOrder_arrow_right"];
    
    if (!cCoupon.coupons.count)
    {
        _couponsCount.hidden = YES;
        _couponsType.text = @"无可用优惠券";
        return;
    }
    
    
    if (cCoupon.usedCoupon == nil) {
        _couponsType.text = @"未使用";
    }
    else
    {
        BK_orders_dic_order_shoppingTicketList_Model *couponInfo = cCoupon.usedCoupon;
        _couponsType.text = [NSString stringWithFormat:@"已减免￥%@",couponInfo.reduceCost];
    }
    _couponsCount.hidden = NO;
    _couponsCount.text = [NSString stringWithFormat:@"%ld张可用",(long)cCoupon.coupons.count];
}


+ (CGFloat)computeHeight:(id)data
{
    return 45;
}
@end
























